package com.aspose.cells;

class zhg implements zafx {
   private int a;
   private RowCollection b;
   private zahr c;
   private short d;
   private short e;
   private boolean f;
   private zfv g;
   private boolean h;
   private boolean i;
   private zahl j;
   private int k;
   private boolean l;
   private zfv m;
   private zp n;
   private Row o;
   private Cell p;
   private int q;

   zhg(Cells var1, boolean var2, int var3) {
      this(var1, -1, (short)-1, -1, (short)-1, var2, var3, false);
   }

   zhg(Cells var1, CellArea var2, boolean var3, int var4) {
      this(var1, var2.StartRow, (short)var2.StartColumn, var2.EndRow, (short)var2.EndColumn, var3, var4, false);
   }

   zhg(Cells var1, int var2, short var3, int var4, short var5, boolean var6, int var7, boolean var8) {
      this.d = var3;
      this.e = var5;
      this.b = var1.getRows();
      if (var1.f().c()) {
         if (var6) {
            this.f = true;
            this.g = new zfv();
         } else {
            this.f = false;
            this.g = null;
         }
      } else {
         this.f = true;
         this.g = null;
      }

      this.c = var1.getRows().a.a(var2, var4, false);
      this.k = -1;
      if (this.c == null) {
         this.l = true;
         this.i = false;
         this.h = false;
         this.a = var7;
      } else {
         this.a(false);
         if (var8) {
            this.h = true;
            this.q = -1;
            this.a = var7 & -2;
            if (this.c.h()) {
               this.i = false;
            } else {
               this.i = true;
            }
         } else {
            this.i = false;
            this.h = false;
            this.a = var7;
         }
      }

   }

   public boolean hasNext() {
      return this.a();
   }

   public Object next() {
      return this.b();
   }

   public void remove() {
      throw new CellsException(19, "Removing cells data while iteration is not supported");
   }

   public boolean a() {
      if (this.l) {
         return false;
      } else {
         if (this.h) {
            this.j.a(this.q, this.k);
         }

         this.m = null;
         this.p = null;
         this.k = this.j.a();
         if (this.k > -1) {
            if (this.h) {
               this.q = this.n.a(this.k);
            }

            return true;
         } else {
            this.o = null;
            if (this.i) {
               this.c.g();
               this.c.a(this.n.h(), this.c.a());
            }

            this.a(true);
            return !this.l;
         }
      }
   }

   public Object b() {
      return this.f();
   }

   private void a(boolean var1) {
      if (!this.c.hasNext()) {
         this.l = true;
      } else {
         this.n = this.c.e();
         this.j = this.n.b(this.d, this.e, false);
         if (this.j != null) {
            if (!var1) {
               return;
            }

            this.k = this.j.a();
            if (this.k > -1) {
               if (this.h) {
                  this.q = this.n.a(this.k);
               }

               return;
            }
         }

         while(this.c.hasNext()) {
            this.n = this.c.e();
            this.j = this.n.b(this.d, this.e, false);
            if (this.j != null) {
               if (!var1) {
                  return;
               }

               this.k = this.j.a();
               if (this.k > -1) {
                  if (this.h) {
                     this.q = this.n.a(this.k);
                  }

                  return;
               }
            }
         }

         this.l = true;
      }
   }

   public zp c() {
      return this.n;
   }

   public Row d() {
      if (this.o == null) {
         this.o = this.c.f();
      }

      return this.o;
   }

   public zfv e() {
      if (this.m == null) {
         if (this.f) {
            this.m = this.n.a(this.k, this.g, this.a);
         } else {
            this.m = this.n.a(this.k, new zfv(), this.a);
         }
      }

      return this.m;
   }

   public Cell f() {
      if (this.p == null) {
         this.p = new Cell(this.d(), this.k, this.e(), this.m == this.g);
      }

      return this.p;
   }
}
